package com.example.task1.ui.AllService.traffic;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.TrafficTheBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import java.util.HashMap;

import retrofit2.Call;

public class TrafficModificationTheActivity extends AppCompatActivity {

    private EditText tvApplyDate;
    private EditText tvAuditOffice;
    private EditText tvContact;
    private EditText tvFileNo;
    private EditText tvIdCard;
    private EditText tvLicenseLevel;
    private EditText tvLicenseNo;
    private EditText tvTimeout;
    private EditText tvVerifyDate;
    private Button btnSave;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_traffic_modificationthe);
        initView();
        ActionBar supportActionBar = getSupportActionBar();
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        supportActionBar.setTitle("新增驾驶证信息");
        business();
    }

    private void business() {
        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveThe();
            }
        });
    }

    private void saveThe() {
        String applyDate = tvApplyDate.getText().toString();
        String auditOffice = tvAuditOffice.getText().toString();
        String contact = tvContact.getText().toString();
        String fileNo = tvFileNo.getText().toString();
        String idCard = tvIdCard.getText().toString();
        String licenseLevel = tvLicenseLevel.getText().toString();
        String licenseNo = tvLicenseNo.getText().toString();
        String timeout = tvTimeout.getText().toString();
        String verifyDate = tvVerifyDate.getText().toString();
        if (TextUtils.isEmpty(applyDate)) {
            tvApplyDate.setError("不能为空");
        } else if (TextUtils.isEmpty(auditOffice)) {
            tvAuditOffice.setError("不能为空");
        } else if (TextUtils.isEmpty(contact)) {
            tvContact.setError("不能为空");
        } else if (TextUtils.isEmpty(fileNo)) {
            tvFileNo.setError("不能为空");
        } else if (TextUtils.isEmpty(idCard)) {
            tvIdCard.setError("不能为空");
        } else if (TextUtils.isEmpty(licenseLevel)) {
            tvLicenseLevel.setError("不能为空");
        } else if (TextUtils.isEmpty(licenseNo)) {
            tvLicenseNo.setError("不能为空");
        } else if (TextUtils.isEmpty(timeout)) {
            tvTimeout.setError("不能为空");
        } else if (TextUtils.isEmpty(verifyDate)) {
            tvVerifyDate.setError("不能为空");
        } else {
            HashMap<String, Object> map = new HashMap<>();
            map.put("applyDate", applyDate);
            map.put("auditOffice", auditOffice);
            map.put("contact", contact);
            map.put("fileNo", fileNo);
            map.put("idCard", idCard);
            map.put("licenseLevel", licenseLevel);
            map.put("licenseNo", licenseNo);
            map.put("timeout", timeout);
            map.put("verifyDate", verifyDate);
            Call<ApiResp> post = Api.api().post(MyApplication.TOKEN, "/prod-api/api/traffic/license", Api.getBody(map));
            Api.send(post, ApiResp.class, new CallBack<ApiResp>() {
                @Override
                public void success(ApiResp data) {
                    MyApplication.show("绑定成功");
                    finish();
                }

                @Override
                public void error(String msg) {

                }
            });
        }
    }

    private void initView() {
        tvApplyDate = (EditText) findViewById(R.id.tv_applyDate);
        tvAuditOffice = (EditText) findViewById(R.id.tv_auditOffice);
        tvContact = (EditText) findViewById(R.id.tv_contact);
        tvFileNo = (EditText) findViewById(R.id.tv_fileNo);
        tvIdCard = (EditText) findViewById(R.id.tv_idCard);
        tvLicenseLevel = (EditText) findViewById(R.id.tv_licenseLevel);
        tvLicenseNo = (EditText) findViewById(R.id.tv_licenseNo);
        tvTimeout = (EditText) findViewById(R.id.tv_timeout);
        tvVerifyDate = (EditText) findViewById(R.id.tv_verifyDate);
        btnSave = (Button) findViewById(R.id.btn_save);
    }
}